package com.grj;


import com.grj.handler.HttpServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * @author grj
 * @description
 * @date 2025-11-16 15:45
 */


public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        // HTTP 编解码器
        pipeline.addLast("httpCodec", new HttpServerCodec());
        // HTTP 消息聚合器
        pipeline.addLast("aggregator", new HttpObjectAggregator(200 * 1024 * 1024));
        // 支持大文件传输
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
        // 自定义业务处理器
        pipeline.addLast("httpHandler", new HttpServerHandler());
    }
}
